# -*- coding:utf-8 -*-
from datetime import timedelta
from apps.v1_0.index.view import main
from apps.v1_0.doc.view import doc
from flask import Flask, current_app, request



def create_app():
    if not current_app:
        app = Flask(__name__)
    else:
        app = current_app
    return app


app = create_app()
app.config.from_object(__name__)
app.debug = True
app.secret_key = "sdfas983w5asdr"
app.permanent_session_lifetime = timedelta(seconds=60 * 60 * 24)

# 首页
app.register_blueprint(main)
app.register_blueprint(doc)



@app.before_request
def request_paras_args():
    qdict = {}
    if request.method == 'GET':
        query = request.args
        for k, v in dict(query).items():
            qdict[k] = v and v[0] or ''
    elif request.method in ('POST', 'PUT', 'DELETE'):
        query = request.form
        for key in query.keys():
            qdict[key] = query.get(key, '')
    request.qdict = qdict
    # log.info("--------------------------")
    # log.info("------------------%s " % request.qdict)
    # log.info("-------------------%s" % request.url)
    print ("-------------------------------")
